/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bean;

import Database.Koneksi;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Yohanes Beny P
 */
public class Barang_Konsumen {

    private String jenisbarang, status;
    private String bobot, ongkos;
    private String noResi, tanggalTerima, tanggalKirim, idKantorCabang;

    public Barang_Konsumen() {
    }

    public Barang_Konsumen(String jenisbarang, String status, String bobot, String ongkos, String noResi, String tanggalTerima, String tanggalKirim, String idKantorCabang) {
        this.jenisbarang = jenisbarang;
        this.status = status;
        this.bobot = bobot;
        this.ongkos = ongkos;
        this.noResi = noResi;
        this.tanggalTerima = tanggalTerima;
        this.tanggalKirim = tanggalKirim;
        this.idKantorCabang = idKantorCabang;
    }

    public ResultSet tampilSemuaBarang() throws SQLException {
        Connection con = Koneksi.open();
        Statement stat = con.createStatement();
        String in = "select * from BARANG_T";
        ResultSet rs = stat.executeQuery(in);
        return rs;
    }

    public ResultSet cariData(String noResi) throws SQLException {
        Connection con = Koneksi.open();
        Statement stat = con.createStatement();
        String in = "select * from BARANG_T where NO_RESI='" + noResi + "'";
        ResultSet rs = stat.executeQuery(in);
        return rs;
    }

    public void terimaData(Barang_Konsumen brg) throws SQLException {
        Connection con = Koneksi.open();
        Statement stat = con.createStatement();
        String in = "insert into BARANG_T(NO_RESI, BIAYA, JENIS_BARANG, BOBOT, ID_KANTOR_CABANG, TANGGAL_KIRIM, TANGGAL_TERIMA, STATUS)"
                + "values('" + brg.getNoResi() + "','" + brg.getOngkos() + "','" + brg.getJenisbarang() + "','"
                + brg.getBobot() + "','" + brg.getIdKantorCabang() + "','" + brg.getTanggalKirim() + "','"
                + brg.getTanggalTerima() + "','" + brg.getStatus() + "')";
        stat.executeUpdate(in);
    }

    public void updateStatus(String noResi, String status) throws SQLException {
        Connection con = Koneksi.open();
        Statement stat = con.createStatement();
        String in1 = "update BARANG_T set STATUS = '" + status + "' where NO_RESI ='" + noResi + "'";
        stat.executeUpdate(in1);
    }

    public void updateTglTerima(String noResi, String tgl) throws SQLException {
        Connection con = Koneksi.open();
        Statement stat = con.createStatement();
        String in1 = "update BARANG_T set TANGGAL_TERIMA = '" + tgl + "' where NO_RESI ='" + noResi + "'";
        stat.executeUpdate(in1);
    }

    public double hitungOngkos(int jenis, double bobot) {
        double harga = 0;
        if (jenis == 1) {
            harga = bobot * 13000;
        } else if (jenis == 2) {
            harga = bobot * 20000;
        } else if (jenis == 3) {
            harga = bobot * 10000;
        }
        return harga;
    }

    public String generateNoResi(Date tgl, String jenis, String cab) throws SQLException {
        Bean.Konsumen kon = new Bean.Konsumen();
        String dat;
        SimpleDateFormat date = new SimpleDateFormat("ddMMyyyy");
        dat = date.format(tgl) + cab + jenis + kon.generateID();
        return dat;
    }

    public String getJenisbarang() {
        return jenisbarang;
    }

    public void setJenisbarang(String jenisbarang) {
        this.jenisbarang = jenisbarang;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getBobot() {
        return bobot;
    }

    public void setBobot(String bobot) {
        this.bobot = bobot;
    }

    public String getOngkos() {
        return ongkos;
    }

    public void setOngkos(String ongkos) {
        this.ongkos = ongkos;
    }

    public String getNoResi() {
        return noResi;
    }

    public void setNoResi(String noResi) {
        this.noResi = noResi;
    }

    public String getTanggalTerima() {
        return tanggalTerima;
    }

    public void setTanggalTerima(String tanggalTerima) {
        this.tanggalTerima = tanggalTerima;
    }

    public String getTanggalKirim() {
        return tanggalKirim;
    }

    public void setTanggalKirim(String tanggalKirim) {
        this.tanggalKirim = tanggalKirim;
    }

    public String getIdKantorCabang() {
        return idKantorCabang;
    }

    public void setIdKantorCabang(String idKantorCabang) {
        this.idKantorCabang = idKantorCabang;
    }
}
